package com.hfut.wxy.service.impl;

import com.hfut.wxy.common.parent.ParentService;
import com.hfut.wxy.common.response.WxyPage;
import com.hfut.wxy.entity.mongo.WxyChat;
import com.hfut.wxy.service.IChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: RyouA
 * @Date: 2020/4/25 - 9:28 下午
 **/
@Service
@Transactional(rollbackFor = Exception.class)
public class ChatService extends ParentService implements IChatService {


    @Override
    public List<WxyChat> getAllChatByOrderId(Integer chatId, WxyPage page) {
        Query query = new Query(Criteria.where("orderId").is(chatId));
        Pageable pageable = WxyPage.getPageable(page, Sort.by(Sort.Order.desc("_id")));
        query.with(pageable);
        return mongoTemplate.find(query,WxyChat.class,"wxyChat");
    }
}
